package com.ogawa.a7517.fragment;

import android.view.View;
import android.widget.TextView;

import com.ogawa.a7517.Constant;
import com.ogawa.a7517.R;
import com.ogawa.a7517.bean.DeviceStateBean;
import com.ogawa.a7517.bean.MassageArmchair;

public class RollHeatFragment extends BaseFragment implements View.OnClickListener {
    private TextView tvHandRoll, tvFootRoll, tvBackHeat, tvKneeHeat;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_senior_roll_heat;
    }

    @Override
    public void initView(View view) {
        tvHandRoll = view.findViewById(R.id.tv_hand_roll);
        tvHandRoll.setOnClickListener(this);
        tvFootRoll = view.findViewById(R.id.tv_foot_roll);
        tvFootRoll.setOnClickListener(this);
        tvBackHeat = view.findViewById(R.id.tv_back_heat);
        tvBackHeat.setOnClickListener(this);
        tvKneeHeat = view.findViewById(R.id.tv_knee_heat);
        tvKneeHeat.setOnClickListener(this);
    }

    @Override
    public void deviceStateChange() {
        super.deviceStateChange();
        if (!isInit) {
            return;
        }
        DeviceStateBean stateBean = MassageArmchair.getInstance().getDeviceStatusBean();
        if (stateBean != null) {
            if (stateBean.getFunctions().getHeatBack() != null) {//背部加热
                int heatBack = Integer.parseInt(stateBean.getFunctions().getHeatBack().getModelValue());
                tvBackHeat.setSelected(heatBack == 1);
            }
            if (stateBean.getFunctions().getKneeHeat() != null) {//膝部加热
                int kneeHeat = Integer.parseInt(stateBean.getFunctions().getKneeHeat().getModelValue());
                tvKneeHeat.setSelected(kneeHeat == 1);
            }
            if (stateBean.getFunctions().getHandScrollButton() != null) {
                int handScrollButton = Integer.parseInt(stateBean.getFunctions().getHandScrollButton().getModelValue());
                tvHandRoll.setSelected(handScrollButton == 1);
            }
            if (stateBean.getFunctions().getFootWheelButton() != null) {
                int footWheelButton = Integer.parseInt(stateBean.getFunctions().getFootWheelButton().getModelValue());
                tvFootRoll.setSelected(footWheelButton == 1);
            }
        } else {
            stateReset();
        }
        int runningStatus = MassageArmchair.getInstance().getRunningStatus();
        if (runningStatus == 0) {
            stateReset();
        }
    }

    private void stateReset() {
        tvHandRoll.setSelected(false);
        tvFootRoll.setSelected(false);
        tvBackHeat.setSelected(false);
        tvKneeHeat.setSelected(false);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.tv_back_heat) {
            activity7517.publish(Constant.HEAT_BACK, "3");
        } else if (id == R.id.tv_knee_heat) {
            activity7517.publish(Constant.KNEE_HEAT, "3");
        } else if (id == R.id.tv_hand_roll) {
            activity7517.publish(Constant.HAND_SCROLL, "3");
        } else if (id == R.id.tv_foot_roll) {
            activity7517.publish(Constant.FOOT_WHEEL, "3");
        }
    }
}
